MODULE = PlPN          PACKAGE = PlPN::ScriptRegistry

#
# Pod::Html is kind of brain-dead:
#
# Place Z<> between function names and parentheses, otherwise Pod::Html
# assumes you meant to put C<...> around it
#
# Put explicit text in all links L<use my text, stupid|some::perl::module>,
# otherwise Pod::Html assumes you want "the X manpage". (Does not apply to
# relative links withing this file.)
#
# It also assumes you want a link if you have C<...> with text matching a
# potential link target. The only way I've found around that is to split it
# up into multiple pieces: C<wo>C<rd>. Looks correct in the resulting HTML,
# but it's ugly to have <code>wo</code><code>rd</code> in the source, and I
# shouldn't have to do it.
#

=head1 NAME

PlPN::ScriptRegistry - The script registry object

=head1 SYNOPSIS

	use PlPN qw(PN);
	
	my $reg = PN->GetScriptRegistry;
	$reg->RegisterRunner($some_id, $some_runner);
	
	# etc.

=head1 DESCRIPTION

Allows access to the Programmer's Notepad script registry from Perl.

This object is not very useful unless you plan to write your own
script runner.

=cut

FALLBACK: TRUE

bool
eq(a,b,swap)
		extensions::IScriptRegistry* a;
		extensions::IScriptRegistry* b;
		IV swap;
	OVERLOAD: ==
	CODE:
		RETVAL = (a == b);
	OUTPUT:
		RETVAL

#
# xsubpp only generates the following code for the module, not for the
# individual packages. In our case, that's less than useful, because the
# module does not, in fact, have overloaded operators.
# See the boot section in the generated code for an explanation of what the
# following code does
#
BOOT:
PL_amagic_generation++;
sv_setsv(
	get_sv( "PlPN::ScriptRegistry::()", TRUE ),
	&PL_sv_yes	// or &PL_sv_no or &PL_sv_undef
);
(void)newXSproto_portable("PlPN::ScriptRegistry::()", XS_PlPN_nil, file, "$$$");

=head1 METHODS

=over

=item AddZ<>($group, $name, $scriptref)

Adds a script to the registry. C<$name> will appear under C<$group> in the
Scripts window; these should be user-friendly strings. C<$scriptref>
is a string in the form C<runnerID:scriptID>. See the
L<PlPN::ScriptRunner|PlPN::ScriptRunner> synopsis for a somewhat contrived
example.

=cut

void
extensions::IScriptRegistry::Add(group, name, scriptref)
		const char* group;
		const char* name;
		const char* scriptref;
	CODE:
		// see if the script has already been added
		if (g_script_tracker.Add(scriptref))
			THIS->Add(group, name, scriptref);

=item RegisterRunnerZ<>($id, $runner)

Registers C<$runner> (a ScriptRunner object) under the C<$id> (a string).

=cut

void
extensions::IScriptRegistry::RegisterRunner(id, runner)
		const char* id;
		PerlScriptRunner* runner;
	CODE:
		THIS->RegisterRunner(id, (extensions::IScriptRunner*)runner);
		runner->SetId(id);
		runner->InUse(true);

=item RemoveRunnerZ<>($id)

Removes the ScriptRunner object registered under C<$id>.

=cut

void
extensions::IScriptRegistry::RemoveRunner(id)
		const char* id;
	CODE:
		PerlScriptRunner* runner = (PerlScriptRunner*)THIS->GetRunner(id);
		runner->InUse(false);
		THIS->RemoveRunner(id);

=item GetRunnerZ<>($id)

Returns the ScriptRunner object registered under C<$id>.

=cut

extensions::IScriptRunner*
extensions::IScriptRegistry::GetRunner(id)
		const char* id;
		const char* CLASS = "PlPN::ScriptRunner";

=item EnableSchemeScriptsZ<>($scheme, $id)

Allows documents with the given scheme to be added to the Scripts window via
the context menu. They will appear in the Scripts window under the group
'User Scripts' with the filename from the tab as the script name.

=cut

void
extensions::IScriptRegistry::EnableSchemeScripts(scheme, runnerId)
		const char* scheme;
		const char* runnerId;

=back

=head1 COPYRIGHT and LICENCE

Copyright (c) 2012 Sean Healy. All rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut
